class Solution:
    def minimumDeletions(self, word: str, k: int) -> int:
        nums = Counter(word).values()
        def calc(v):
            res = 0
            for x in nums:
                if x < v: res += x
                elif x > v + k: res += x - v - k
            return res
        return min(calc(i) for i in range(len(word) + 1))